home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-wos-src / machines / amigawos / libsrc / stdio / _read.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  950b  |  56 lines

  1. /*
  2. ** vbcc-PowerOpen/WarpOS Lowlevel read() function
  3. **
  4. ** v0.2 29.10.98 phx
  5. **      disabled errno usage
  6. ** v0.1 31.07.98 phx
  7. */
  8.  
  9. #include <stdio.h>
  10. #ifdef _ERRNO_
  11. #include <errno.h>
  12. #endif
  13.  
  14. #include <powerpc/powerpc.h>
  15. #include <clib/powerpc_protos.h>
  16.  
  17. extern APTR DOSBase;
  18.  
  19.  
  20. long _read(char *fh,void *buf,long size)
  21. {
  22.   struct PPCArgs pa;
  23.   long n;
  24.  
  25. #ifdef _ERRNO_
  26.   if (!fh) {
  27.     errno = EBADF;
  28.     return (EOF);
  29.   }
  30.   if (size <= 0) {
  31.     errno = EINVAL;
  32.     return (EOF);
  33.   }
  34. #endif
  35.  
  36.   pa.PP_Code = DOSBase;
  37.   pa.PP_Offset = -42;  /* _LVORead */
  38.   pa.PP_Flags = pa.PP_StackSize = 0;
  39.   pa.PP_Stack = NULL;
  40.   pa.PP_Regs[PPREG_D1] = (ULONG)fh;
  41.   pa.PP_Regs[PPREG_D2] = (ULONG)buf;
  42.   pa.PP_Regs[PPREG_D3] = (ULONG)size;
  43.   pa.PP_Regs[PPREG_A6] = (ULONG)DOSBase;
  44.   Run68K(&pa);
  45.  
  46. #ifdef _ERRNO_
  47.   if ((n = (long)pa.PP_Regs[PPREG_D0]) == -1) {
  48.     errno = EIO;
  49.     return (EOF);
  50.   }
  51.   return (n);
  52. #else
  53.   return ((long)pa.PP_Regs[PPREG_D0]);
  54. #endif
  55. }
  56.